package com.zlzxm.shoesmarket.viewmodel;

import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.zlzxm.shoesmarket.util.RxAndroidHelp;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityOperateSize;
import com.zlzxm.shoesmarket.viewmodel.entity.EntityTransfer;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.disposables.Disposable;

/**
 * CREATE BY zlzxm ON 4/20/21
 */
public class VMSaveEdit extends ViewModel {

    private MutableLiveData<EntityTransfer> liveGoodsInfo = new MutableLiveData<>();

    private MutableLiveData<List<EntityOperateSize>> liveSaveSize = new MutableLiveData<>();


    public MutableLiveData<EntityTransfer> getLiveGoodsInfo() {
        return liveGoodsInfo;
    }

    public MutableLiveData<List<EntityOperateSize>> getLiveSaveSize() {
        return liveSaveSize;
    }

    public void requestSizeInfo(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                        liveSaveSize.setValue(createTestInfoData());

                    }
                });




    }



    public void requestSize(){

        Observable.timer(3, TimeUnit.SECONDS)
                .compose(RxAndroidHelp.turn())
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(@NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@NonNull Long aLong) {

                    }

                    @Override
                    public void onError(@NonNull Throwable e) {

                    }

                    @Override
                    public void onComplete() {


                    }
                });





    }


    //<editor-fold defaultState="collapsed" desc="测试">



    private List<EntityOperateSize> createTestInfoData(){

        List<EntityOperateSize> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {

            EntityOperateSize entityOperateSize = new EntityOperateSize();

            entityOperateSize.setNote("sss");
            entityOperateSize.setNum(i);
            entityOperateSize.setPrice(""+i);
            entityOperateSize.setSize(""+i);


            list.add(entityOperateSize);
        }




        return  list;

    }




    // </editor-fold>
}
